<?php

// start session
session_start();

// connect to database
$conn_str = 'host=dbsrv1.cdf.toronto.edu dbname=csc309g23 user=csc309g23 password=ipheid5h';
$conn = pg_connect($conn_str);

// query database
$query = 'INSERT INTO rosters (username,gameid, organizer,status) VALUES (\'' . $_POST['username'] . '\',' . $_POST['gameid'] . ',\'t\',1)';
$result = pg_query($conn, $query);

echo $query;

if ($result) { // if succesfully update roster record - i.e accepted invite
    // go back to page from which user logged in
    header('Location: ' . $_SERVER['HTTP_REFERER']);
}
?>
